web/src/pages/[...listing].astro

352 lines · 9073 bytes

  1---
  2
  3import Layout from '@layouts/Layout.astro';
  4import Button from '@components/form/Button.astro';
  5import Main from '@components/scafold/MainCard.astro';
  6import ServiceList from '@components/things/ServiceList.astro';
  7import Comments from '@components/things/Comments.svelte';
  8import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro';
  9import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro';
 10import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro';
 11import type { AwesomePrivacy, Section, Service } from '../types/Service';
 12import { fetchData, slugify } from '@utils/fetch-data';
 13import { fetchGitHubStats } from '@utils/fetch-repo-info';
 14import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy';
 15import { fetchWebsiteInfo } from '@utils/fetch-website-info';
 16import { parseMarkdown, formatLink } from '@utils/parse-markdown';
 17
 18interface Props extends Service {
 19  slug: string;
 20  parentSection: Section;
 21  categoryName: string;
 22}
 23
 24const {
 25  name,
 26  description,
 27  url,
 28  github,
 29  tosdrId,
 30  icon,
 31  followWith,
 32  securityAudited,
 33  openSource,
 34  acceptsCrypto,
 35  parentSection,
 36  categoryName,
 37} = Astro.props;
 38
 39
 40/**
 41 * Make a list of keywords, for the <meta keywords> tag
 42 */
 43const makeKeyWordTag = () => {
 44  const keywords: string[] = [];
 45  // keywords.push(`free and open source ${title} software`);
 46  // keywords.push(`private ${title} comparison`);
 47  // (alternativeTo || []).forEach((alt: string) => {
 48  //   keywords.push(`privacy-respecting ${alt} alternative`);
 49  //   keywords.push(`free open source ${alt} alternative`);
 50  // });
 51  // (services || []).forEach((serv: Service) => {
 52  //   keywords.push(serv.name);
 53  // });
 54  // keywords.push('ad free');
 55  // keywords.push('open source software');
 56  // keywords.push('privacy respecting apps');
 57  return keywords.join(', ');
 58};
 59
 60/**
 61 * Make a page title
 62 */
 63const makePageTitle = () => {
 64  return `${name} | ${parentSection.name} | ${categoryName} | Awesome Privacy`;
 65};
 66
 67/**
 68 * Make a string page intro, for the description tag
 69 */
 70const makeDescriptionTag = () => {
 71  let description = `A list of privacy respecting ${name}. `;
 72  // if (services && services.length > 0) {
 73  //   const serviceList = services.map((serv: Service) => serv.name);
 74  //   description += `Compare ${serviceList.join(', ')} and more private apps and services. `
 75  // } else {
 76  //   description += `Find private apps and services. This section is still a work in progress. `;
 77  // }
 78  // description += 'All this, and much more at Awesome Privacy, '
 79  // description += 'the free and open source list of private software alternatives.';
 80  return description;
 81};
 82
 83// Return a list of Services, except for the currtent one
 84const filterServices = () => {
 85  return parentSection.services.filter((service: Service) => service.name !== name);
 86};
 87
 88export async function getStaticPaths() {
 89  const pages = await fetchData().then((data) => {
 90    const results: Array<Props> = [];
 91    if (!data || !data.categories) return results;
 92    (data as AwesomePrivacy).categories.forEach((category) => {
 93      category.sections.forEach((section) => {
 94        const services = (section.services || []).map((service) => {
 95          return {
 96            slug: `${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`,
 97            parentSection: section,
 98            categoryName: category.name,
 99            ...service,
100          };
101        });
102        results.push(...services);
103      });
104      
105    });
106    return results;
107  });
108
109  return pages.map((props: Props) => {
110    return {params: { listing: props.slug }, props };
111  });
112}
113
114// const makePaginationLinks = () => {
115//   const index = otherSections.findIndex(section => section.name === title);
116//   const previousSection = index >  0 ? otherSections[index -  1].name : null;
117//   const nextSection = index < otherSections.length -  1 ? otherSections[index +  1].name : null;
118//   return { previous: previousSection, next: nextSection };
119// };
120
121// const { previous, next } = makePaginationLinks();
122
123
124// Fetch detailed data about the services GitHub repo, privacy policy and website
125const githubData = github ? await fetchGitHubStats(github) : null;
126const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null;
127const websiteData = (url && !url.includes('github.com')) ? await fetchWebsiteInfo(url) : null;
128
129---
130
131<Layout title={makePageTitle()} keywords={makeKeyWordTag()} description={makeDescriptionTag()} >
132  <main>
133    <section>
134      <div class="service-head">
135        <h2>{name}</h2>
136        <span class="url-wrap">
137          <a class="service-url" href={url}>{formatLink(url)}</a>
138          <span class="follow-with">{followWith}</span>
139        </span>
140      </div>
141      <div class="breadcrumbs">
142        <span>
143          <a href="/">Awesome Privacy</a>
144          ➔ <a href={`/${slugify(categoryName)}`}>{categoryName}</a>
145          ➔ <a href={`/${slugify(categoryName)}/${slugify(parentSection.name)}`}>{parentSection.name}</a>
146          ➔ <a href={`/${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`}>{name}</a>
147        </span>
148      </div>     
149      <div class="intro">
150        <img 
151          width="60"
152          height="60"
153          loading="lazy"
154          decoding="async"
155          class="service-icon"
156          alt={`${name} Icon`}
157          data-service-url={formatLink(url)}
158          src={icon || `https://icon.horse/icon/${formatLink(url)}`}
159        />
160        <p class="description" set:html={parseMarkdown(description)}></p>
161      </div>
162    </section>
163    { privacyData && (
164      <section>
165        <h3>{name} Privacy Policy</h3>
166        <PrivacyPolicyDetails privacyData={privacyData} />
167      </section>
168    )}
169    { github && githubData && (
170      <section class="github-wrap">
171        <h3>{name} Source Code</h3>
172        <GitHubDetailedInfo gitHubData={githubData} repo={github} />
173      </section>
174    )}
175
176    { websiteData && (
177      <section>
178        <h3>{name} Website</h3>
179        <WebsiteDetailedInfo url={url} websiteInfo={websiteData} />
180      </section>
181    )}
182    <section>
183      <h3>{name} Reviews</h3>
184      <Comments client:visible />
185    </section>
186    <section>
187      <h3>More {parentSection.name}</h3>
188      <ServiceList
189        services={filterServices()}
190        subHeading={true}
191        noGitHubMetrics={true}
192        buttonLink={`/${slugify(categoryName)}/${slugify(parentSection.name)}`}
193        categoryName={categoryName}
194        sectionName={parentSection.name}
195      />
196    </section>
197  </main>
198</Layout>
199
200<style lang="scss">
201
202main {
203  margin: 2rem auto;
204  padding: 1rem;
205  width: 1000px;
206  max-width: calc(100% - 5rem);
207  position: relative;
208}	
209
210section {
211  margin: 1rem 0 4rem 0;
212  padding: 1rem;
213  min-height: 8rem;
214  position: relative;
215  border: 2px solid var(--foreground);
216  box-shadow: 6px 6px 0 var(--foreground);
217  background: var(--accent-fg);
218
219}
220
221h3 {
222    font-size: 2rem;
223    margin: -2rem 0 1rem -2rem;
224    box-shadow: 6px 6px 0 var(--foreground);
225    background: var(--accent);
226    color: var(--accent-fg);
227    width: fit-content;
228    padding: 0.25rem 0.5rem;
229  }
230
231.service-head {
232  h2 {
233    font-size: 3rem;
234    margin: 0;
235  }
236  .url-wrap {
237    display: flex;
238    align-items: center;
239    gap: 0.5rem;
240    a {
241      font-size: 1.2rem;
242    }
243    .follow-with {
244      font-style: italic;
245      opacity: 0.6;
246    }
247  }
248  
249}
250
251.breadcrumbs {
252  opacity: 0.5;
253  font-size: 0.8rem;
254  position: absolute;
255  right: 1rem;
256  top: 1rem;
257  a {
258    color: var(--foreground);
259    transition: all 0.15s ease-in-out;
260    
261    &:hover {
262      color: var(--accent);
263    }
264  }
265}
266
267.intro {
268  font-size: 1.2rem;
269  font-style: italic;
270  opacity: 0.7; 
271  display: flex;
272  align-items: center;
273  gap: 0.5rem;
274}
275
276.pagination-navigation {
277  display: flex;
278  justify-content: space-between;
279  align-items: center;
280  padding: 1rem 0;
281  :global(.button) {
282    min-width: 120px;
283    width: fit-content;
284    padding: 0.25rem 1rem;
285    text-align: right;
286    &:first-child { text-align: left; }
287    p {
288      margin: 0;
289      font-weight: normal;
290      font-size: 1rem;
291    }
292    span {
293      font-size: 0.8rem;
294    }
295    
296  }
297  .nothing {
298    width: 120px;
299  }
300  .go-to-category {
301    color: var(--foreground);
302    font-size: 0.8rem;
303    opacity: 0.5;
304    @media (max-width: 768px) {
305      display: none;
306    }
307  }
308}
309
310
311
312.further-info, .notable-mentions, .word-of-warning {
313  h3 {
314    font-size: 1.4rem;
315    margin: 1rem 0;
316  }
317  :global(p) {
318    font-size: 0.9rem;
319    opacity: 0.7; 
320    :global(strong) {
321      font-weight: 500;
322    }
323    :global(a) {
324      color: var(--foreground);
325      transition: all 0.15s ease-in-out;
326      &:hover {
327        color: var(--accent);
328      }
329    }
330  }
331  :global(strong) {
332    font-weight: 500;
333  }
334  :global(h4) {
335    font-size: 1.2rem;
336    margin: 0.5rem 0 0 0;
337  }
338  :global(ul) {
339    list-style: circle;
340    padding-left: 1rem;
341    font-size: 0.9rem;
342    opacity: 0.7;
343    li {
344      margin-bottom: 0.25rem;
345      :global(p) {
346        display: inline;
347      }
348    }
349  }
350}
351
352</style>